// CDCT.h : interface of the CDCT class
//
/////////////////////////////////////////////////////////////////////////////

#ifndef __CDCT__
#define __CDCT__

#include "stdafx.h"

#define N (__int16)8
//#define Ndef 8
//#define Ndef2 64

class CDCT : public CObject
{
//    DECLARE_SERIAL(CDCT)
// Construction
public:
	CDCT ();
    ~CDCT();

// Attributes
public:       
	 double PI;

    /**
     * DCT Block Size - default 8
     */
     //__int16 N;//Utilizar define

    /**
     * Image Quality (0-25) - default 25 (worst image / best compression)
     */
     __int16 QUALITY;

    /**
     * Image width - must correspond to imageArray bounds - default 320
     */
//     __int16 ROWS;

    /**
     * Image height - must correspond to imageArray bounds - default 200
     */
//     __int16 COLS;

    /**
	* The ZigZag matrix: (N*N)*2
     */
     __int16 zigZag[N*N][2];

    /**
     * Cosine matrix. N * N.
     */
	double c[N][N];

    /**
     * Transformed cosine matrix, N*N.
     */
     double cT[N][N];

    /**
     * Quantitization Matrix.
     */
     __int16 quantum[N][N];

    /**
     * DCT Result Matrix
     */
     //__int16 resultDCT[N][N];

// Operations
public:
	__int16* forwardDCT(BYTE *input);
	void forwardDCT(BYTE *input, __int16 *output);
	__int16** forwardDCTInterFrame(__int16 **input);
	__int16* dequantitizeImage(__int16* inputData, BOOL zigzag);
	void dequantitizeImage(__int16* inputData, BOOL zigzag, __int16 *outputData);
	__int16* quantitizeImage(__int16 *inputData, BOOL zigzag);
	void quantitizeImage(__int16 *inputData, BOOL zigzag, __int16 *outputData);
//	__int16* compressImage(__int16* QDCT, BOOL log);
//	__int16* decompressImage(__int16* DCT, BOOL log);
	BYTE* inverseDCT(__int16 *input);
	void inverseDCT(__int16 *input, BYTE *output);
	void huffmanCodeBloq(__int16 *quantitiza, DWORD &posResultado, LPBYTE resultado);
	void difCodeBloq(__int16 *quantitiza, DWORD &posResultado, LPBYTE resultado);
//	BOOL ParecidoDifCodeBloq(__int16 valor, __int16 valor2);
	void huffmanDecodeBloq(LPBYTE inputCode, LPBYTE outputCode);
	BOOL difDecodeBloq(LPBYTE pInputCode, DWORD dwTam, __int16 *pResultado);
	void setQuality(__int16 quality);
	void initMatrix();

private:
	void initZigZag();
	__int16 bytetoInt(BYTE *bitSet);
	BYTE* inttoByte(__int16 count);
	void inttoByte(__int16 count, BYTE *bitSet);

};

#endif // __CDCT__
